package com.sc.nft.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.WantBuyDTO;
import com.sc.nft.entity.ScrollWantSell;
import com.sc.nft.enums.WantBuyOrderStatusEnum;
import com.sc.nft.enums.WantSellOrderStatusEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ScrollWantBuy;
import com.sc.nft.mapper.ScrollWantBuyMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 卷轴商店求购表(sc_scroll_want_buy)数据DAO
 *
 * @author zxy
 * @since 2024-09-04 02:15:00
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class ScrollWantBuyDao extends ServiceImpl<ScrollWantBuyMapper, ScrollWantBuy> {

    public ScrollWantBuy getByOrderNo(String orderNo) {
        return lambdaQuery().eq(ScrollWantBuy::getOrderNo, orderNo).one();
    }

    public Page<ScrollWantBuy> myPage(Long userId,Page page) {
        return lambdaQuery().eq(ScrollWantBuy::getShopUserId,userId).last(" order by field(status,3,1,5,0,4),id desc").page(page);
    }
    public Page<WantBuyDTO> wantBuyPage(Long userId,Long shopId, boolean inDao, Page page){
        return baseMapper.wantBuyPage(page,userId,shopId,inDao);
    }

    public Integer getCountByShopId(Long shopId) {
        return lambdaQuery().eq(ScrollWantBuy::getShopId, shopId).in(ScrollWantBuy::getStatus, WantBuyOrderStatusEnum.IN_BUY,WantBuyOrderStatusEnum.WAIT_PAY).count();
    }
}